from django.template import Library
from web import models
from django.shortcuts import reverse

register = Library()


@register.inclusion_tag('inclusion/all_project_list.html')
def project_list(request):
    # 当前项目
    # 我创建的
    my_project = models.Project.objects.filter(creator=request.tracer.user)
    # 我加入的
    join_project = models.ProjectUser.objects.filter(user=request.tracer.user)

    return {'my': my_project, 'join': join_project, 'request': request}


@register.inclusion_tag('inclusion/detailed_list.html')
def detailed_list(request):
    # 拼凑菜单详细
    # 前端需要的数据 title 项目id url
    dic = [
        {'title': '概览', 'url': reverse('dashboard', kwargs={'project_id': request.tracer.project.id})},
        {'title': '问题', 'url': reverse('issues', kwargs={'project_id': request.tracer.project.id})},
        {'title': '统计', 'url': reverse('statistics', kwargs={'project_id': request.tracer.project.id})},
        {'title': 'wiki', 'url': reverse('wiki', kwargs={'project_id': request.tracer.project.id})},
        {'title': '文件', 'url': reverse('file', kwargs={'project_id': request.tracer.project.id})},
        {'title': '设置', 'url': reverse('settings', kwargs={'project_id': request.tracer.project.id})},

    ]
    # 默认选中当前的菜单
    # request.path_info与dic里面的url匹配，配到到了，添加一个样式
    for item in dic:
        if request.path_info == item['url']:
            item['class'] = 'li_active'
    return {'dic': dic, 'request': request}
